<?php
/**
 * It shows the catalog products of the current category or subcategory:
 * $_GET["category_id"]
 *
*/
# User session management
require('includes/user_manage.php');

require_once('includes/classes/category.php');

if ($user->isAdmin) { 
	$my_catalog=new admin_category();
}
else {
	$my_catalog=new category();
}

$my_catalog->id=$_GET["category_id"];

$my_catalog->db_load_items();

$serItems=json_encode($my_catalog);
?>
<table class="product" myProperty="itemsList">
	<?php
		if (isset($_SERVER['HTTP_USER_AGENT']) && $server->bot_detect($_SERVER['HTTP_USER_AGENT'])) {
			#We will procced to show the products for the current category
			foreach ($my_catalog->items as $my_item) {
				include($server->get_path_name("small_item.php"));
			}
		}
		if ($user->isAdmin) include($server->get_path_name('small_item_admin_tp.php'));
		else include($server->get_path_name('small_item_tp.php'));
	?>
	
</table>
<form><input id="serItems" type="hidden" value="<?php print htmlentities($serItems); ?>"></form>
<script language="javascript">
	//For some reason there is an error when trying to load json directly from javascript
	var catalogPointer=myCatalog;
	catalogPointer=catalogPointer.moveToChildren("selected");
	if (catalogPointer.myCategory.selected) {
		catalogPointer=catalogPointer.moveToChildren("selected");
	}
	catalogPointer.loadItems(document.getElementById("serItems").value);
	catalogPointer.loadItemsListView("containerItems");
	catalogPointer.refreshItemsListView("containerItems");
</script>